﻿//
// Created by work on 24-6-6.
//

#ifndef IOT_PLAT_CRTMODELYXINFO_H
#define IOT_PLAT_CRTMODELYXINFO_H

#include "CRtModelSigBase.h"

class CRtModelYxInfo : public CRtModelSigBase{
    Q_OBJECT
public:
    enum EModelYxCol {
            EValues = 7
        };

        struct SYxValue {
            int value = 0;
            QString v_descr = "test";
            QJsonObject v_image = QJsonObject();
            QJsonObject toJson()const {
                QJsonObject obj;
                obj["value"] = value;
                obj["v_descr"] = v_descr;
                obj["v_image"] = v_image;
                return obj;
            }
            void fromJson(QJsonObject obj) {
                value = obj["value"].toInt();
                v_descr = obj["v_descr"].toString();
                v_image = obj["v_image"].toObject();
            }
        };
	std::vector<SYxValue> values;
    static std::map<CRtModelYxInfo::EModelYxCol, QString> rtModelYxColToStringMap;
    static std::map<EModelYxCol, QString> yxColFieldsNameMap;
    static std::map<CRtModelYxInfo::EModelYxCol, CValue::EValueType> rtYxDataTypeByField;

    explicit CRtModelYxInfo(QObject *parent = nullptr);
public:
    QJsonArray valuesToJson()const;
    void valuesFromJson(QJsonArray json);

    virtual QString getFieldNameByCol(int col)override;

    virtual QVariant getFieldValueByFielddName(const QString& name)override;

    virtual void setFieldValueByCol(int col, const QVariant& value)override;

    virtual QJsonObject toJson()override;

    virtual void fromJson(const QJsonObject &obj)override;

    virtual QSharedPointer<IModel> createEmpty()override;

    virtual bool sync(bool dir = true) override;

#define YX_ENUM                     CRtModelYxInfo::EModelYxCol
#define yxFieldName(type)           CRtModelYxInfo::rtModelYxColToStringMap.find(type)->second
#define yxColFieldName(type)        CRtModelYxInfo::yxColFieldsNameMap.find(type)->second
#define yxDataTypeByField(type)     CRtModelYxInfo::rtYxDataTypeByField.find(type)->second
#define YX_COL_SIZE                 (SIGBASE_COL_SIZE + rtModelYxColToStringMap.size())
};

#endif //IOT_PLAT_CRTMODELYXINFO_H
